class MessagesController < ApplicationController

  before_filter :login_required, :find_user

  def new
    @message = Message.new
  end

  def create
    @message = Message.new(params[:message])
    respond_to do |format|
      if @message
        UserMailer.deliver_message(:message => @message,
                                   :from => current_user,
                                   :to => @user,
                                   :link => new_profile_message_url(current_user.login))
        flash[:notice] = 'Message was sent.'
        format.html { redirect_to profile_url(@user.login) }
      else
        format.html { render :action => "new" }
      end
    end
  end

end
